<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var waysToMakeFair = function (nums) {
      let oddR = 0, evenR = 0, oddL = 0, evenL = 0
      for (let i = 0; i < nums.length; i++) {
        i & 1 ? oddR += nums[i] : evenR += nums[i]
      }
      let ans = 0
      for (let i = 0; i < nums.length; i++) {
        i & 1 ? oddR -= nums[i] : evenR -= nums[i]
        oddL + evenR == oddR + evenL && ans++
        i & 1 ? oddL += nums[i] : evenL += nums[i]
      }
      return ans
    };
    console.log(waysToMakeFair([2, 1, 6, 4]));
  </script>
</body>

</html>